package ex4;

public class Reader implements Print {
	
	private String name;	
	private Book [] books;
	
	
	public Reader(String name) {
		this.name = name;
		books = new Book[4];
	}
	
	public void takeBook(Book book){
		
		for ( int i = 0; i < books.length; i++){
			if (books[i] == null && book.isAvailableBook()){
				books[i] = book;
				books[i].setReader(this);
				break;
			}
			
			
		}
	}
	
	public void returnBook(Book book){
		for ( int i = 0; i < books.length; i++){
			if (books[i].equals(book)){	
				books[i] = null;
				break;
			}
			
				
		}
	}
	
	


	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public Book[] getBooks() {
		return books;
	}


	public void setBooks(Book[] books) {
		this.books = books;
	}
	
	public String toString(){
		
		System.out.print(this.name);
		return " ";
	}
	
	public void printBooks(){
		System.out.println(" Books list of " + this.getName());
		for (int i = 0; i < books.length; i++){
			if (books[i] != null){
			System.out.println(books[i]);
			}
		}
		
	}
	
	

}
